package com.davidk.survey.client.root;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.smartgwt.client.util.SC;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class RootView extends Composite implements RootViewInterface {

	private VLayout body = new VLayout();
	private VLayout menu = new VLayout();
	private HLayout title = new HLayout();

	public RootView() {
		initWidget(new SimplePanel());

		menu.setWidth(200);
		menu.setPadding(10);
		title.setHeight(30);
		title.setPadding(10);
		body.setPadding(5);

		VLayout vl = new VLayout();
		HLayout hl = new HLayout();

		hl.setStyleName("cw-DockPanel");
		hl.setMargin(5);
		hl.ensureDebugId("cwDockPanel");
		hl.setHeight100();
		hl.setMembers(menu, body);

		vl.setMembers(title, hl);
		vl.setWidth100();
		vl.setHeight100();
		vl.draw();
	}

	public void showMessage(String msg) {
		SC.say(msg);
	}

	Canvas curBody = null;

	public void setBody(Canvas newBody) {
		if (newBody != curBody) {
			System.out.println("RootView:setBody " + newBody);
			if (curBody != null) {
				body.removeMember(curBody);
			}
			curBody = newBody;
			body.addMember(newBody);
		}
	}

	public void setMenu(Canvas myMenu) {
		menu.removeMembers(menu.getMembers());
		menu.addMember(myMenu);
	}

	public void setTitle(Canvas w) {
		title.removeMembers(title.getMembers());
		title.addMember(w);
	}

	public Widget getViewWidget() {
		return this;
	}

}
